#include <chrono>
#include <iomanip>
#include <iostream>
using namespace std;

#include <glog/logging.h>

#if GLOG_USE_GLOG_EXPORT
void MyPrefixFormatter(std::ostream &s, const google::LogMessage &m, void * /*data*/)
{
    s << "[" << setw(4) << 1900 + m.time().year() << setw(2) << 1 + m.time().month() << setw(2) << m.time().day() << ' ' << setw(2)
      << m.time().hour() << ':' << setw(2) << m.time().min() << ':' << setw(2) << m.time().sec() << "." << setw(6) << m.time().usec() << ' '
      << setfill(' ') << setw(5) << m.thread_id() << setfill('0') << ' ' << m.basename() << ':' << m.line() << "]["
      << google::GetLogSeverityName(m.severity())[0] << "]";
}
#endif

int main(int argc, char *argv[])
{
    FLAGS_max_log_size              = 1800;
    FLAGS_logtostdout               = false;
    FLAGS_colorlogtostdout          = true;
    FLAGS_colorlogtostderr          = true;
    FLAGS_stop_logging_if_full_disk = true;
    FLAGS_alsologtostderr           = true;

    google::InitGoogleLogging(argv[0]);
    google::SetLogDestination(google::GLOG_INFO, "/mnt/glog_test/logInfo");
#if GLOG_USE_GLOG_EXPORT
    // 此处设置只清理 info 日志
    google::EnableLogCleaner(std::chrono::hours(24) * 3);
    google::InstallPrefixFormatter(&MyPrefixFormatter);
#endif

    for (int i = 0; i < 100000; i++) {
        LOG(INFO) << "hello, world, Info";
        LOG(WARNING) << "hello, world, Warning";
        LOG(ERROR) << "hello, world, Error";
    }
    return 0;
}
